import java.security.PublicKey;
import java.util.Base64;

/**
 * @ClassName MainTest
 * @Description TODO
 * @Author 赵雷棚
 * @Date 2024/6/26 14:43
 **/
public class MainTest {
    public static void main(String[] args) throws Exception {

        // 加载证书并获取公钥（示例路径需替换为实际证书路径）
        PublicKey publicKeyFromCert = CertificateExample.loadPublicKeyFromCertificate("mycertificate.pem");

        // 需要加密的信息
        String message = "This is a secret message.";

        // 使用从证书中获取的公钥加密信息
        byte[] encryptedMessage = RSAEncryptDecrypt.encrypt(publicKeyFromCert, message);
        System.out.println("Encrypted Message: " + Base64.getEncoder().encodeToString(encryptedMessage));

        // 假设这是你的私钥（在实际应用中应安全存储）
        // PrivateKey privateKey = ...;

        // 解密信息
        // String decryptedMessage = RSAEncryptDecrypt.decrypt(privateKey, encryptedMessage);
        // System.out.println("Decrypted Message: " + decryptedMessage);
    }
}
